﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RSPJ.Struct;

namespace RSPJ.Function
{
    public class funcKT
    {
        public Files Landsat4_KT(Files file)
        {
            Files outFile = file.Clone();
            outFile.IntArray = new double[6, file.Head.Lines, file.Head.Samples];
            double[,] L4 = new double[6, 6] {
                {  0.3037, 0.2793, 0.4743, 0.5585, 0.5082, 0.1863 },
                { -0.2848,-0.2435,-0.5436, 0.7243, 0.0840,-0.1800 },
                {  0.1509, 0.1973, 0.3279, 0.3406,-0.7112,-0.4572 },
                {  0.8832,-0.0819,-0.4580,-0.0032,-0.0563, 0.0130 },
                {  0.0573,-0.0260, 0.0335,-0.1943, 0.4766,-0.8545 },
                {  0.1238,-0.9038, 0.4041, 0.0573,-0.0261, 0.0240 }
             };

            for (int j = 0; j < file.Head.Lines; j++)
            {
                for (int k = 0; k < file.Head.Samples; k++)
                {
                    for (int i = 0; i < file.Head.Bands; i++)
                    {//进行K-T变换，将变换后的数据存入矩阵Array
                        if (i == 5)//如果是第六波段，则退出，进行下一个波段的循环
                            continue;
                        if (i == 6) //如果是第七波段，还是用第六行的参数
                            outFile.IntArray[5, j, k] = (L4[i - 1, 0] * file.IntArray[0, j, k] + L4[i - 1, 1] * file.IntArray[1, j, k] + L4[i - 1, 2] * file.IntArray[2, j, k] + L4[i - 1, 3] * file.IntArray[3, j, k] + L4[i - 1, 4] * file.IntArray[4, j, k] + L4[i - 1, 5] * file.IntArray[6, j, k]);
                        else
                            outFile.IntArray[i, j, k] = (L4[i, 0] * file.IntArray[0, j, k] + L4[i, 1] * file.IntArray[1, j, k] + L4[i, 2] * file.IntArray[2, j, k] + L4[i, 3] * file.IntArray[3, j, k] + L4[i, 4] * file.IntArray[4, j, k] + L4[i, 5] * file.IntArray[6, j, k]);
                    }

                }
            }
            return outFile;
        }

        public Files Landsat5_KT(Files file)
        {
            Files outFile = file.Clone();
            outFile.IntArray = new double[6, file.Head.Lines, file.Head.Samples];
            double[,] L5 = new double[6, 6]{
                { 0.2909, 0.2493, 0.4806, 0.5568, 0.4438, 0.1706},
                {-0.2728,-0.2174,-0.5508, 0.7221, 0.0733,-0.1648},
                { 0.1446, 0.1761, 0.3322, 0.3396,-0.6210,-0.4186},
                { 0.8461,-0.0731,-0.4640,-0.0032,-0.0492, 0.0119},
                { 0.0549,-0.0232, 0.0339,-0.1937, 0.4162,-0.7823},
                { 0.1186,-0.8069, 0.4094, 0.0571,-0.0228,-0.0220}
                };

            for (int j = 0; j < file.Head.Lines; j++)
            {
                for (int k = 0; k < file.Head.Samples; k++)
                {
                    for (int i = 0; i < file.Head.Bands; i++)
                    {//进行K-T变换，将变换后的数据存入矩阵Array
                        if (i == 5)//如果是第六波段，则退出，进行下一个波段的循环
                            continue;
                        if (i == 6) //如果是第七波段，还是用第六行的参数
                            outFile.IntArray[5, j, k] = (L5[i - 1, 0] * file.IntArray[0, j, k] + L5[i - 1, 1] * file.IntArray[1, j, k] + L5[i - 1, 2] * file.IntArray[2, j, k] + L5[i - 1, 3] * file.IntArray[3, j, k] + L5[i - 1, 4] * file.IntArray[4, j, k] + L5[i - 1, 5] * file.IntArray[6, j, k]);
                        else
                            outFile.IntArray[i, j, k] = (L5[i, 0] * file.IntArray[0, j, k] + L5[i, 1] * file.IntArray[1, j, k] + L5[i, 2] * file.IntArray[2, j, k] + L5[i, 3] * file.IntArray[3, j, k] + L5[i, 4] * file.IntArray[4, j, k] + L5[i, 5] * file.IntArray[6, j, k]);
                    }

                }
            }
            return outFile;
        }

        public Files Landsat7_KT(Files file)
        {
            Files outFile = file.Clone();
            outFile.IntArray = new double[6, file.Head.Lines, file.Head.Samples];
            double[,] L7 = new double[6, 6]{
                { 0.3561, 0.3972, 0.3904, 0.6966, 0.2286, 0.1596},
                {-0.3344,-0.3544,-0.4556, 0.6966,-0.0242,-0.2630},
                { 0.2626, 0.2141, 0.0926, 0.0656,-0.7629,-0.5388},
                { 0.0805,-0.0498, 0.1950,-0.1327, 0.5752,-0.7775},
                {-0.7252,-0.0202, 0.6683, 0.0631,-0.1494,-0.0274},
                { 0.4000,-0.8172, 0.3832, 0.0602,-0.1095, 0.0985}
                };

            for (int j = 0; j < file.Head.Lines; j++)
            {
                for (int k = 0; k < file.Head.Samples; k++)
                {
                    for (int i = 0; i < file.Head.Bands; i++)
                    {//进行K-T变换，将变换后的数据存入矩阵Array
                        if (i == 5)//如果是第六波段，则退出，进行下一个波段的循环
                            continue;
                        if (i == 6) //如果是第七波段，还是用第六行的参数
                            outFile.IntArray[5, j, k] = (L7[i - 1, 0] * file.IntArray[0, j, k] + L7[i - 1, 1] * file.IntArray[1, j, k] + L7[i - 1, 2] * file.IntArray[2, j, k] + L7[i - 1, 3] * file.IntArray[3, j, k] + L7[i - 1, 4] * file.IntArray[4, j, k] + L7[i - 1, 5] * file.IntArray[6, j, k]);
                        else
                            outFile.IntArray[i, j, k] = (L7[i, 0] * file.IntArray[0, j, k] + L7[i, 1] * file.IntArray[1, j, k] + L7[i, 2] * file.IntArray[2, j, k] + L7[i, 3] * file.IntArray[3, j, k] + L7[i, 4] * file.IntArray[4, j, k] + L7[i, 5] * file.IntArray[6, j, k]);
                    }

                }
            }
            return outFile;
        }

    }

}
